package bancosys.tec.security.impl;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Keeps the number of users currently logged in the system.
 * 
 * @author Marcio Ribeiro (mmr)
 * @created Dec 9, 2011
 */
public class UsersLoggedCounter {
    private final AtomicInteger users = new AtomicInteger(0);

    /**
     * Increment the number of logged in users. Should be called when the user logs in.
     * 
     * @return the incremented value.
     */
    public int increment() {
        return this.users.getAndIncrement();
    }

    /**
     * Decrement the number of logged in users. Should be called when the user logs off the system.
     * 
     * @return the decremented value.
     */
    public int decrement() {
        return this.users.getAndDecrement();
    }

    /**
     * @return number of user currently logged in.
     */
    public int getUsers() {
        return this.users.intValue();
    }
}
